/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package DB;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 *
 * @author Tomas
 */
public class DBConnector {
    private static final String DRIVER = "jdbc:sqlserver://balder.ucn.dk:1433";
    private static final String DATABASENAME = ";databaseName=DM73_4";
    private static final String USERNAME = ";user=DM73_4";
    private static final String PASSWORD = ";password=MaaGodt";
    private static final String DRIVERLOC = "com.microsoft.sqlserver.jdbc.SQLServerDriver";

    private static Connection con;
    private static DBConnector instance = null;

    private DBConnector(){
        String url = DRIVER+DATABASENAME+USERNAME+PASSWORD;

        try{
            Class.forName(DRIVERLOC);
        }catch(Exception e){
            System.out.println(e.getMessage());
        }

        try{
            con = DriverManager.getConnection(url);
            con.setAutoCommit(true);
        }catch(Exception e){
            System.out.println(e.getMessage());
        }
    }
    public static void closeConnection(){
        try{
            con.close();
        }catch(Exception e){
            System.out.println(e.getMessage());
        }
    }
    public Connection getDBConnection(){
        return con;
    }
    public static DBConnector getInstance(){
        if(instance == null){
            instance = new DBConnector();
        }
        return instance;
    }
}
